package com.major.mytomcat.servlet;

import com.major.mytomcat.Container;
import com.major.mytomcat.Request;
import com.major.mytomcat.Response;

import java.util.Map;

public class UserServlet extends HttpServlet {
    @Override
    public void doGet(Request request, Response response) {

        String cookie = request.getHeaders().get("cookie");
        System.out.println(cookie);
        if (cookie == null){
            response.write("<h1>您没有登陆</h1>");
        }else {
            String sessionId = cookie.split("=")[1];
            Map<String, Object> session = Container.SESSIONS.get(sessionId);

            if ("zhangsan" == session.get("user")){
                response.write("<h1>您好"+session.get("user")+"</h1>");
            }else {
                response.write("请先登录");
            }


        }

        response.write("<h1>User,User,User</h1>");

    }
}
